Ext.define("app.customer.archive.form", {
	extend : 'Ext.window.Window',
	title : '编辑信息',
	height : 600,
	width : 800,
	closable : true,
	resizable : false,
	modal : true,
	constrain : true,
	plain : true,
	layout : {
		type : 'border'
	},
	requires : [ 'app.customer.archive.field' ],
	initComponent : function() {
		var me = this;
		me.form = me.createForm();
		Ext.apply(me, {
			items : [ me.form ],
			buttons : [ {
				text : '确认',
				bodyStyle : 'padding:0 0 0 5px',
				handler : function() {
					me.submitForm();
				}
			}, {
				text : '关闭',
				bodyStyle : 'padding:0 0 0 5px',
				handler : function() {
					me.close();
				}
			} ]
		});
		me.callParent(arguments);
	},
	submitForm : function() {
		var me = this;
		var params = {};
		if (me.customerId) {
			params['customerId'] = me.customerId;
		}
		evt.submit(me.form, systemUrl + '/boyon/customer/'
				+ me.urlType + '/editor', params, function() {
			Ext.Msg.alert('提示', '操作成功');
			me.parentTarget.reloadStore();
			me.close();
		});
	},
	loadData : function(form) {
		var me = this;
		var customerId = me.customerId;
		if (!customerId) {
			return;
		}
		utils.loadform({
			form : me,
			model : 'app.customer.model.customer',
			url : systemUrl + '/boyon/customer/' + me.urlType + '/find',
			extraParams : {
				'customerId' : me.customerId
			},
			fn : function(rec) {
				me.form.getForm().loadRecord(rec);
			}
		});
	},
	createForm : function() {
		var me = this;
		var fields = me.createField();
		var form = Ext.create('Ext.form.Panel', {
			layout : 'column',
			region : 'center',
			bodyStyle:'overflow-x:hidden;overflow-y:auto;',
			items : fields,
			listeners : {
				afterrender : function() {
					me.loadData(form);
				}
			}
		});
		return form;
	},
	createField : function() {
		var me = this;
		var array = new Array();
		utils.pushfieldarray(array, '1', {
			name : 'customerName',
			beforeLabelTextTpl : required,
			fieldLabel : '客户名称',
			allowBlank : false,
			columnWidth : .33,
			maxLength : 32
		});
		utils.pushfieldarray(array, '1', {
			name : 'customerShort',
			beforeLabelTextTpl : required,
			fieldLabel : '简称',
			columnWidth : .33,
			maxLength : 32
		});
		utils.pushfieldarray(array, '4', {
			name : 'parentCustomerId'
		});
		if (me.customerId) {
			utils.pushfieldarray(array, '1', {
				name : 'parentCustomerName',
				fieldLabel : '上级代理',
				columnWidth : 0.33,
				readOnly : true
			});
		} else {	
			utils.pushfieldarray(array, 'app.customer.archive.field', {
				name : 'parentCustomerName',
				fieldLabel : '上级代理',
				parentTarget : me,
				pannelParam : {
					urlType : me.urlType
				},
				columnWidth : 0.33
			});
		}
		utils.pushfieldarray(array, 'app.widget.value', {
			name : 'customerType',
			beforeLabelTextTpl : required,
			fieldLabel : '客户类型',
			valueField : 'value',
			displayField : 'displayName',
			valueType : 11,
			columnWidth : .33,
			parentTarget : me,
			editable : false,
			allowBlank : false
		});
		var categoryValue = utils.getValueField('t' + 15, me.urlType);
		utils.pushfieldarray(array, '1', {
			name : 'categoryName',
			beforeLabelTextTpl : required,
			fieldLabel : '客户分类',
			columnWidth : .33,
			readOnly : true,
			value : categoryValue
		});
		utils.pushfieldarray(array, '1', {
			name : 'linkMan',
			fieldLabel : '联系人',
			columnWidth : .33,
			maxLength : 16
		});
		utils.pushfieldarray(array, '1', {
			name : 'phone',
			fieldLabel : '电话',
			columnWidth : .33,
			maxLength : 18
		});
		utils.pushfieldarray(array, '1', {
			name : 'address',
			fieldLabel : '地址',
			columnWidth : .66,
			maxLength : 64
		});
		utils.pushfieldarray(array, '6', {
			name : 'info',
			fieldLabel : '介绍',
			columnWidth : 1,
			maxLength : 64
		});
		utils.pushfieldarray(array, '6', {
			name : 'remark',
			fieldLabel : '备注',
			columnWidth : 1,
			maxLength : 32
		});
		utils.pushfieldarray(array, '1', {
			name : 'regionCode',
			fieldLabel : '地区',
			columnWidth : .33,
			maxLength : 6
		});
		utils.pushfieldarray(array, '1', {
			name : 'www',
			fieldLabel : '网址',
			columnWidth : .33,
			maxLength : 64
		});
		utils.pushfieldarray(array, '1', {
			name : 'fax',
			fieldLabel : '传真',
			columnWidth : .33,
			maxLength : 18
		});
		utils.pushfieldarray(array, '1', {
			name : 'postcode',
			fieldLabel : '邮政编码',
			columnWidth : .33,
			maxLength : 8
		});
		utils.pushfieldarray(array, '3', {
			name : 'creditPrice',
			fieldLabel : '信用额度',
			columnWidth : .33,
			maxLength : 10
		});
		utils.pushfieldarray(array, 'app.widget.value', {
			name : 'payType',
			beforeLabelTextTpl : required,
			fieldLabel : '支付方式',
			valueField : 'value',
			displayField : 'displayName',
			valueType : 12,
			columnWidth : .33,
			parentTarget : me,
			editable : false
		});
		utils.pushfieldarray(array, 'app.widget.value', {
			name : 'settlementType',
			beforeLabelTextTpl : required,
			fieldLabel : '结算方式',
			valueField : 'value',
			displayField : 'displayName',
			valueType : 13,
			columnWidth : .33,
			parentTarget : me,
			editable : false
		});
		utils.pushfieldarray(array, 'app.widget.value', {
			name : 'invoiceType',
			beforeLabelTextTpl : required,
			fieldLabel : '发票类型',
			valueField : 'value',
			displayField : 'displayName',
			valueType : 14,
			columnWidth : .33,
			parentTarget : me,
			editable : false
		});
		utils.pushfieldarray(array, '1', {
			name : 'bankName',
			fieldLabel : '开户行',
			columnWidth : .33,
			maxLength : 16
		});
		utils.pushfieldarray(array, '1', {
			name : 'accountName',
			fieldLabel : '户名',
			columnWidth : .33,
			maxLength : 16
		});
		utils.pushfieldarray(array, '1', {
			name : 'account',
			fieldLabel : '开户账号',
			columnWidth : .33,
			maxLength : 32
		});
		return array;
	},
	callBackCustomer : function(rec) {
		var me = this;
		me.form.getForm().findField('parentCustomerId').setValue(rec.get('customerId'));
		me.form.getForm().findField('parentCustomerName').setValue(rec.get('customerName'));
	}
});